package per.sunmes.cl.g.data.cards;

import per.sunmes.cl.g.actor.Card;
import per.sunmes.cl.g.actor.Zone;
import per.sunmes.cl.g.data.CardEffect;
import per.sunmes.cl.g.i.CallBack;
import per.sunmes.cl.g.screen.GameScreen;
import per.sunmes.cl.g.sys.LM;
import per.sunmes.cl.g.sys.RandU;
import per.sunmes.cl.g.sys.U;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.scenes.scene2d.Group;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.ui.Image;

public class CardEffect4 implements CardEffect {
	// 基本类型
	// 占领当前区域
	@Override
	public void effect(GameScreen gameScreen, Zone selfZone, Card cardSelf) {
		selfCardMoveLandEffect(gameScreen, selfZone, cardSelf, new CallBack() {
			@Override
			public void call() {
				selfZone.setCard(cardSelf);

				int y = RandU.rand(0, LM.mapYCount);
				int x = RandU.rand(0, LM.mapXCount);
				Zone zone = selfZone.getZoneMap()[x][y];

				Image p = U.image("dialog/sign_error.png");
				zone.getParent().addActor(p);
				p.setColor(Color.ORANGE);
				U.center(p, zone);
				p.addAction(Actions.sequence(Actions.delay(0.2f),
						Actions.fadeOut(0.3f), Actions.removeActor()));

				if (zone.getCard() != null) {
					Card card = zone.getCard();
					zone.setCard(null);
					card.setPlayer(cardSelf.getPlayer());
					card.changeBackToCard();
					card.updateToPlayerCard();
					cardSelf.getPlayer().getHandCards().add(card);
					U.actorKeepRectChangeParent(card, gameScreen.getGameGroup());
					gameScreen.resetPlayerHandCard(cardSelf.getPlayer());
				}
			}
		});
		// ///
		gameScreen.delayActionExecuteNextRound(0.4f);
	}

	@Override
	public void preEffect(GameScreen gameScreen, Zone selfZone, Card cardSelf,
			Group previewGroup) {
		// preEffectCardSelfLand(gameScreen, selfZone, cardSelf, previewGroup);
	}

	@Override
	public boolean isCouldPutToZone(Zone zone) {
		return zone.getCard() == null;
	}

}
